<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form id="login">
        <table>
            <tr>
                <td>用户名</td>
                <td>
                    <input type="text" name="username" id="username">
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td>
                    <input type="password" name="password" id="password">
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <button>登录</button>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

<script src="/jscode/js/tools.js"></script>
<script>
    let login = document.getElementById('login');

    login.onsubmit = function(e)
    {
        e.preventDefault();
        
        // String对象提供函数 trim => 把左右的空格去掉
        let username = document.getElementById('username').value.trim();
        let password = document.getElementById('password').value.trim();
        
        if(!username)
        {
            alert('请输入用户名');

            return false;
        }

        if(!password)
        {
            alert('请输入密码');

            return false;
        }

        // 组装存储信息数据
        let data = {
            id:1,
            username
        }

        // 设置本地存储
        // JSON对象，stringify => 把数据转成json字符串
        localStorage.setItem('business',JSON.stringify(data));

        Module.notice('登录成功','4.html');
}
</script>